package chapter04

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

type Article struct {
	Id      int    `form:"-" binding:"required"` // 绑定校验，id不能为空
	Title   string `form:"title"`
	Content string `form:"content"`
	Desc    string `form:"desc"`
}

func ToValidData(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "chapter04/valid_data.html", nil)
}

func DoValidData(ctx *gin.Context) {
	var article Article
	err := ctx.ShouldBind(&article)
	fmt.Println(err)
	fmt.Println(article)

	ctx.String(http.StatusOK, "成功", nil)
}
